// TerminalDlg.cpp : implementation file
//

#include "stdafx.h"
#include "dtdemo.h"
#include "TerminalDlg.h"
#include "Codelib.h"


// CTerminalDlg dialog

IMPLEMENT_DYNAMIC(CTerminalDlg, CDialog)

CTerminalDlg::CTerminalDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTerminalDlg::IDD, pParent)
	,m_pClient(NULL)
{

}

CTerminalDlg::~CTerminalDlg()
{
}

void CTerminalDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CTerminalDlg, CDialog)
	ON_BN_CLICKED(IDC_EQUIPMENT_UPDATE, &CTerminalDlg::OnBnClickedEquipmentUpdate)
	ON_BN_CLICKED(IDC_SETNICKNAME, &CTerminalDlg::OnBnClickedSetnickname)
	ON_BN_CLICKED(IDC_SENDGPS, &CTerminalDlg::OnBnClickedSendgps)
	ON_BN_CLICKED(IDC_SENDALARM, &CTerminalDlg::OnBnClickedSendalarm)
	ON_BN_CLICKED(IDC_SENDEVENT, &CTerminalDlg::OnBnClickedSendevent)
END_MESSAGE_MAP()


// CTerminalDlg message handlers

void CTerminalDlg::OnBnClickedEquipmentUpdate()
{
	// TODO: Add your control notification handler code here
	if(m_pClient != NULL)
	{
		mdt_device d1;
		d1.connectstatus = eCS_Connected;
		d1.deviceid = "1";
		d1.devicename = "N95-1";
		d1.devicestatus = eDS_Idle;
		d1.devicetype = "N95";
		d1.nettype = "GSM";
		d1.phonenumber = "13146783210";
		d1.testplanversion = "9";
		d1.teststarttime = "20031213T183002";
		vmdt_devices ddd;
		ddd.push_back(d1);
		m_pClient->SendDeviceStatus(ddd);
	}
}

void CTerminalDlg::OnBnClickedSetnickname()
{
	// TODO: Add your control notification handler code here
	CWnd *pwnd = GetDlgItem(IDC_EDIT1);
	CString nickname;
	pwnd->GetWindowText(nickname);
	if(m_pClient != NULL)
	{
		m_pClient->SetNickName(CCodeLib::UnicodeToUTF8(nickname.GetString()));
	}
}

void CTerminalDlg::OnBnClickedSendgps()
{
	// TODO: Add your control notification handler code here
	if(m_pClient != NULL)
	{
		m_pClient->SendGpsInfo(1.0, 2.0);
	}
}

void CTerminalDlg::OnBnClickedSendalarm()
{
	// TODO: Add your control notification handler code here
	if(m_pClient != NULL)
	{
		mdt_alarm alarm;
		alarm.code = "test";
		alarm.level = "1";
		alarm.name = "down";
		alarm.time = "20120921T090000";
		m_pClient->SendAlarmInfo("1", alarm);
	}
}

void CTerminalDlg::OnBnClickedSendevent()
{
	// TODO: Add your control notification handler code here
	if(m_pClient != NULL)
	{
		mdt_event evt;
		evt.category = "test";
		evt.code = "12";
		evt.name = "down";
		evt.time = "20120921T090000";
		m_pClient->SendEventInfo("1", evt);
	}
}
